import jdk.swing.interop.SwingInterOpUtils;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-07-07
 * Time: 23:16
 */
//https://leetcode.cn/problems/symmetric-tree/
    //给你一个二叉树的根节点 root ， 检查它是否轴对称。
class TreeNode {
    int val;
    public TreeNode left;
    public TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class Test {
    public static boolean isSymmetric(TreeNode root) {
        if(root==null){
            return true;
        }
        return fun(root.left,root.right);
    }

    public static boolean fun(TreeNode q,TreeNode p){
        if(p==null&&q==null){
            return true;
        }
        if(p==null||q==null){
            return false;
        }
        if(p.val==q.val){
            return fun(p.left,q.right)&&fun(p.right,q.left);
        }
        else{
            return false;
        }
    }

    public static void main(String[] args) {
        TreeNode A1 = new TreeNode(1);
        TreeNode A2 = new TreeNode(2);
        TreeNode A3 = new TreeNode(2);
        TreeNode A4 = new TreeNode(4);
        TreeNode A5 = new TreeNode(4);
        TreeNode A6 = new TreeNode(4);
        TreeNode A7 = new TreeNode(4);
        A1.left=A2;A1.right=A3;
        A2.left=A4;A2.right=A5;
        A3.left=A6;A3.right=A7;
        System.out.println(isSymmetric(A1));
        A7.val=1;
        System.out.println(isSymmetric(A1));
    }

}
